﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DomainModel;
using Utils;
using WebUI.Utils;

namespace WebUI.Models
{
    public class IndResumeViewModel: BaseViewModel
    {
        public IndResumeViewModel()
            : base()
        { }

        public IndResumeViewModel(string useName, int loginID)
            : base(new { UserName = useName, LoginID =  loginID})
        {

        }

        public Boolean IsIndAccountOwner { get; set; }
        public string AvatarUrl { get; set; }
        public Login Login { get; set; }
        public Ind Ind { get; set; }
        //public List<Shot> ShotList { get; set; }
        public List<Skill> SkillList { get; set; }

        public Boolean IsIndSaved { get; set; }
        public Boolean IsSentRecently { get; set; }

        protected override void SetVarsWhichDependOnDynamicParams(dynamic dynParams)
        {
            //init data
            string userName = dynParams.UserName;
            int loginID = dynParams.LoginID;

            IsIndAccountOwner = Identity.IsIndAccountOwner(userName);
            
            IndLogin indLogin = DataUtils.GetIndLoginByID(loginID);
            Login = indLogin.Login;
            Ind = indLogin.Ind;
            
            SkillList = DataUtils.GetList<Skill>(ConstUtils.SP_GetSkillListByID, new { IndID = Ind.IndID });
            AvatarUrl = ImageUtils.GetAvatarRelativeUrl(AvatarType.IndAvatar, Ind.IndID, AvatarSizeEnum.Avatar_80x80, Ind.AvatarFileExtension);

            if (Identity.IsLoggedIn)
            {
                SavedInd savedInd = DataUtils.GetOne<SavedInd>(ConstUtils.SP_GetOneSavedInd, new { SaveLoginID = Identity.LoginID, SavedLoginID = loginID });
                IsIndSaved = savedInd != null && savedInd.SavedIndID > 0;

                EmailLog emailLog = DataUtils.GetOne<EmailLog>(ConstUtils.SP_GetOneEmailLog, new { SenderLoginID = Identity.LoginID, ReceiverLoginID = loginID });
                IsSentRecently = ViewModelUtils.IsSentRecently(emailLog);
            }
            else
            {
                IsIndSaved = false;
                IsSentRecently = false;
            }
        }

        
    }
}